﻿namespace block_explorer.NoiseSystem.Nodes
{
    class Fractal : INode
    {
        INode mSource;
        int mOctaves;
        double mAmplitude;
        double mGain;
        double mFrequency;
        double mLacunarity;

        public Fractal(INode source, int octaves, double amplitude, double gain, double frequency, double lacunarity)
        {
            mSource = source;
            mOctaves = octaves;
            mAmplitude = amplitude;
            mGain = gain;
            mFrequency = frequency;
            mLacunarity = lacunarity;
        }

        public double Value(double x, double y, double z)
        {
            double a = 0.0f;
            double f = mFrequency;
            double g = mAmplitude;
            for (int i = 0; i < mOctaves; i++)
            {
                a += g * mSource.Value(x * f, y * f, z * f);
                f *= mLacunarity;
                g *= mGain;
            }
            return a;
        }
    }
}
